using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.Windows;
namespace MicroMsg.UI.UserContrl
{
	public class ItemCacheService
	{
		private const string TAG = "ItemCacheService";
		private List<FrameworkElement> txt_l_list = new List<FrameworkElement>();
		private List<FrameworkElement> txt_r_list = new List<FrameworkElement>();
		private List<FrameworkElement> img_l_list = new List<FrameworkElement>();
		private List<FrameworkElement> img_r_list = new List<FrameworkElement>();
		private List<FrameworkElement> voice_l_list = new List<FrameworkElement>();
		private List<FrameworkElement> voice_r_list = new List<FrameworkElement>();
		private List<FrameworkElement> time_info_list = new List<FrameworkElement>();
		private List<FrameworkElement> custom_l_list = new List<FrameworkElement>();
		private List<FrameworkElement> custom_r_list = new List<FrameworkElement>();
		private List<FrameworkElement> GetListByType(Chat_UI_Type ui_type)
		{
			switch (ui_type)
			{
			case Chat_UI_Type.TXT_L:
				return this.txt_l_list;
			case Chat_UI_Type.TXT_R:
				return this.txt_r_list;
			case Chat_UI_Type.IMG_L:
				return this.img_l_list;
			case Chat_UI_Type.IMG_R:
				return this.img_r_list;
			case Chat_UI_Type.CUSTOM_L:
				return this.custom_l_list;
			case Chat_UI_Type.CUSTOM_R:
				return this.custom_r_list;
			case Chat_UI_Type.VOICE_L:
				return this.voice_l_list;
			case Chat_UI_Type.VOICE_R:
				return this.voice_r_list;
			case Chat_UI_Type.TIME_INFO:
				return this.time_info_list;
			default:
				return null;
			}
		}
		private Chat_UI_Type GetTypeByElement(FrameworkElement frameworkElement_0)
		{
			if (frameworkElement_0 is ChatLeftText)
			{
				return Chat_UI_Type.TXT_L;
			}
			if (frameworkElement_0 is ChatRightText)
			{
				return Chat_UI_Type.TXT_R;
			}
			if (frameworkElement_0 is ChatLeftImg)
			{
				return Chat_UI_Type.IMG_L;
			}
			if (frameworkElement_0 is ChatRightImg)
			{
				return Chat_UI_Type.IMG_R;
			}
			if (frameworkElement_0 is ChatLeftVoice)
			{
				return Chat_UI_Type.VOICE_L;
			}
			if (frameworkElement_0 is ChatRightVoice)
			{
				return Chat_UI_Type.VOICE_R;
			}
			if (frameworkElement_0 is ChatTimeItem)
			{
				return Chat_UI_Type.TIME_INFO;
			}
			return Chat_UI_Type.UNKNOW;
		}
		private FrameworkElement CreatNewByType(Chat_UI_Type ui_type)
		{
			switch (ui_type)
			{
			case Chat_UI_Type.TXT_L:
				return new ChatLeftText();
			case Chat_UI_Type.TXT_R:
				return new ChatRightText();
			case Chat_UI_Type.IMG_L:
				return new ChatLeftImg();
			case Chat_UI_Type.IMG_R:
				return new ChatRightImg();
			case Chat_UI_Type.CUSTOM_L:
				return new CustomSmileyItemLeft();
			case Chat_UI_Type.CUSTOM_R:
				return new CustomSmileyItemRight();
			case Chat_UI_Type.VOICE_L:
				return new ChatLeftVoice();
			case Chat_UI_Type.VOICE_R:
				return new ChatRightVoice();
			case Chat_UI_Type.TIME_INFO:
				return new ChatTimeItem();
			default:
				return new ChatLeftText();
			}
		}
		public FrameworkElement GetItemByType(Chat_UI_Type ui_type)
		{
			List<FrameworkElement> listByType = this.GetListByType(ui_type);
			if (listByType == null)
			{
				return null;
			}
			if (listByType.get_Count() <= 0)
			{
				Log.smethod_5("ItemCacheService", "create type:" + ui_type);
				return this.CreatNewByType(ui_type);
			}
			FrameworkElement result = listByType.get_Item(0);
			listByType.RemoveAt(0);
			return result;
		}
		public void RestoreItem(FrameworkElement frameworkElement_0)
		{
			Chat_UI_Type typeByElement = this.GetTypeByElement(frameworkElement_0);
			if (typeByElement == Chat_UI_Type.UNKNOW)
			{
				return;
			}
			List<FrameworkElement> listByType = this.GetListByType(typeByElement);
			if (listByType == null)
			{
				return;
			}
			if (listByType.get_Count() >= 20)
			{
				return;
			}
			listByType.Add(frameworkElement_0);
		}
	}
}
